/*	Sequence class definition
 *  It always starts by the first child, updating each one.
 *	If any child finishes with failure, the Sequence fails, and we bail.
 *	When a child finishes with success, we select the next child as the update victim.
 *	If we have finished updating the last child, the Sequence returns with success.
 *
 *	Example of use:			SCVBuildBuilding which implements Sequence
 *					/			|				\
 *	start:	MoveToBuildSite	  BuildBuilding		GatherResources		end
 *	Original credit for a java implementation to: http://magicscrollsofcode.blogspot.com/2010/12/behavior-trees-by-example-ai-in-android.html
*/

#ifndef SEQUENCE_H_
#define SEQUENCE_H_

#include "ParentBehavior.h"

class Sequence : public ParentBehavior
{
public:

    /**
     * Creates a new instance of the Sequence class
     */
	Sequence()	{}

    /**
     * A child finished with failure.
     * We failed to update the whole sequence. Bail with failure.
     */
    void BehaviorFailed() 
    {
        control->FinishWithFailure();
    }

    /**
     * A child has finished with success
     * Select the next one to update. If it's the last, we have finished with success.
     */
    void BehaviorSucceeded() 
    {
		int curPos = control->GetCurrentBehaviorPos();
		if( curPos == (control->GetSubBehaviors()->size() - 1))
        {
            control.FinishWithSuccess();
        }
        else
        {
            control->IterateBehavior();
			if(!control->GetCurrentBehavior()->CheckConditions())
            {
                    control->FinishWithFailure();
            }
        }
    }
}




protected:


private:


};

#endif
